package com.pine.sunshineelder.login.web.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.pine.sunshineelder.common.StringHelper;
import com.pine.sunshineelder.common.dto.JSONResponse;
import com.pine.sunshineelder.common.dto.UserContext;
import com.pine.sunshineelder.login.service.LoginService;
import com.pine.sunshineelder.login.vo.LoginVo;
/**
 * 
 * @author 苟瑞雪
 *
 */


@RestController
@RequestMapping("/api")
public class LoginHandler implements StringHelper{
	@Autowired
	LoginService service;
	
	@PostMapping("/session")
	public JSONResponse registerUser(String account,String password) throws Exception {
		 UserContext login = service.login(account, password);
		 LoginVo lv=new  LoginVo();
		 lv.setId(login.getId());
		 lv.setName(login.getName());
		 lv.setRole(login.getRole());
		 lv.setAccount(login.getAccount());
		return JSONResponse.ok(lv);
	}

}
